package com.mc.servlet;

import com.mc.VO.MatchVO;
import com.mc.bean.Match;
import com.mc.bean.MatchState;
import com.mc.service.MatchService;
import com.mc.service.MatchStateService;
import com.mc.service.MatchVOService;
import com.mc.service.impl.MatchServiceImpl;
import com.mc.service.impl.MatchStateServiceImpl;
import com.mc.service.impl.MatchVOServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description 学生报名控制器
 * @author wangcf
 * @date 2023/2/15 17:59
 * @version 1.0
 */
@WebServlet("/apply.action")
public class ApplyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        MatchService matchService=new MatchServiceImpl();
        MatchVOService matchVOService=new MatchVOServiceImpl();
        MatchStateService matchStateService=new MatchStateServiceImpl();
        String midStr=req.getParameter("mid");
        System.out.println(midStr);
        Match match=matchService.findByMid(Integer.parseInt(midStr));
        req.setAttribute("match",match);
        MatchState matchState=matchStateService.findByMSid(match.getMsid());
        req.setAttribute("msname",matchState.getMsname());
        List<MatchVO> matchVOList=matchVOService.findByMid(Integer.parseInt(midStr));
        req.setAttribute("teamlist",matchVOList);
        req.getRequestDispatcher("apply.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
